<?php
/**
 * Created by PhpStorm.
 * User: wjj
 * Date: 2016/11/1
 */

namespace app\logic;

use app\models\Adv;
use app\models\Area;
use app\models\Category;
use app\models\GoodsCategory;

class CategoryLogic
{
    public function getCategory($category_id){
        if($category_id){
            return Category::find()->select('category_id,category_pic,category_name')
                ->where(['parent_id'=>$category_id,'level'=>2])
                ->orderBy('category_sort asc')
                ->asArray()->all();
        }else{
            $goodsCategory = GoodsCategory::find()->asArray()->all();
            $category_id = array_unique(array_column($goodsCategory,'first_category_id'));
            return Category::find()->select('category_id,category_pic,category_name')
                ->where(['level'=>$category_id,'level'=>1,'category_id'=>$category_id])
                ->orderBy('category_sort asc')
                ->asArray()->all();
        }
    }

}